<%@ 
	page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"
%>

<%!

	String type = "type";
	String value = null;
	boolean checked = false;
	String date = "";
	
	final static java.lang.String[] dagen = {"Maandag", "Dinsdag", "Woensdag", "Donderdag", "Vrijdag"};
	
	private static java.lang.String getDataBox(java.lang.String method, String date)
	{
		
		int day_cal = java.util.Calendar.getInstance().get(java.util.Calendar.DAY_OF_WEEK);
		int today = day_cal - 2;
		
		int sel_day = today;
		
		if (!date.equals(""))
		{
			int temp = -1;
			try {
				temp = Integer.parseInt(date);
			} catch (NumberFormatException e)
			{}
			if (temp >= 0) sel_day = temp;
		}
		
		if ((sel_day < 0) || (sel_day > 4)) sel_day = 0;
		
		String combo = "<select name=" + method + "_date>\n";
		for (int i = 0; i < dagen.length; i++) {
			String extra = "";
			String value = dagen[i];
			if (today == i) {
				if ((today >= 0) && (today <= 4)) value = "Vandaag";
			}
			if (sel_day == i)
			{
				extra = "selected";
			}
			combo += "<option value=\"" + i + "\" " + extra + ">" + value + "</option>\n";
		}
		combo += "</select>";
		//System.out.println(combo);
		return combo;
	};
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="java.util.Date"%>

<%
	if (request.getMethod().equals("POST"))
	{
		type = request.getParameter("type");
		value = request.getParameter("value");
		if (request.getParameter("schema") != null) checked = true;
		date = request.getParameter("value_date");
	}

%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="./style/titamo.css" />
<title>Titamo - Artesis Rooster Check</title>
</head>
<body>

<div id="main">
	<div id="header">
		<img id="logo" src="./images/tlogo.png" />
		<div id="artesis"><img src="./images/artesis.png" id="artesislogo"></div>
		<div class="floatclearer"></div>
	</div>
	<div id="input">
		<form action="./index.jsp" method="post">
		<table>
			<tr>
				<td>
					type
   					<select name="type">
   		  				<option value="group" <% if (type.equals("group")) { %> selected <% } %> >Klas</option>
   		  				<option value="instructor" <% if (type.equals("instructor")) { %> selected <% } %> >Docent</option>
   						<option value="course" <% if (type.equals("course")) { %> selected <% } %> >Vak</option>
 					</select>
        
        			zoek
        
        			<input type="text" name="value" <% if (value != null) { %> value="<%=value %>" <% } %> />
        
       				op
        
        			<%=getDataBox("value", date) %>
        
				</td>
				<td><input type="submit" value="toon" /></td>
			</tr>
			<tr>
				<td class="rights">
					<input type="checkbox" name="schema" <% if (checked) { %> checked <% } %> />tijdschema
				</td>
			</tr>
		</table>
        </form>
	</div>
	<div id="content">
<%
	if ((request.getParameter("page") != null) && (request.getParameter("page").equals("error")))
	{
%>
		<jsp:include page='./pages/errorHandler.jsp' />
<%
	}
	else
	{
		if (request.getMethod().equals("POST"))
		{	
%>
		<jsp:include page='./pages/resultHandler.jsp' />
<% 
		}
	}
%>	
	</div>
	<div id="footer">
		<div id="closer">&copy titamo - group e</div>
	</div>
</div>
</body>
</html>